<?php
function setEmail($email,$username){
        date_default_timezone_set("Asia/Shanghai");//设定时区东八区
        require_once('/Public/email/class.phpmailer.php');
        include('/Public/email/class.smtp.php');
        $mail = new PHPMailer(); //new一个PHPMailer对象出来
        $mail->CharSet = "UTF-8";//设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
        $mail->IsSMTP(); // 设定使用SMTP服务
        $mail->SMTPDebug = 0;                     // 启用SMTP调试功能
        // 1 = errors and messages
        // 2 = messages only
        $mail->SMTPKeepAlive = true;
        $smtpserver = "smtp.qq.com";
        $port = "465";
        $smtpuser = "781502032@qq.com";
        $smtppwd = "qshszaewhgbtbfjd";

        $mail->SMTPAuth = true;                  // 启用 SMTP 验证功能

        //是否为安全链接
     
        $mail->SMTPSecure = "ssl";                 // 安全协议
     
        $mail->Host =$smtpserver;      // SMTP 服务器
        $mail->Port = $port;                   // SMTP服务器的端口号
        $mail->Username = $smtpuser;  // SMTP服务器用户名
        $mail->Password = $smtppwd;            // SMTP服务器密码
        $mail->SetFrom($smtpuser, "song");
        // $mail->AddReplyTo("281@qq.com", "邮件回复人的名称");
        $mail->Subject =  "验证邮件"; //邮件标题
        $mail->ishtml(true); 
        $mail->addembeddedimage('Public/home/img/photo_1.jpg', 'photo_1', 'Public/home/img/photo_1.jpg');
        $mail->Body = '你好, <b>朋友</b>! <br/>这是一封来自<a href="com" 
target="_blank">songzhilai</a>的邮件！我们还要做个邮箱激活，以及邮箱找回密码的功能<br/>
<img alt="helloweba" style="width:1600px;height:800px" src="cid:photo_1">';; //邮件内容
        $mail->AltBody = "www.song.com"; // optional, comment out and test
        /*$mail->AddAddress('song@aomai.com.au','songzhilai');*/
        $mail->AddAddress($email,$username);
        $status_eamil  =  $mail->Send();
    
        if (!$status_eamil) {
           // echo "Mailer Error: " . $mail->ErrorInfo;
            //return array("error"=>0,"message"=>"Mailer Error: " . $mail->ErrorInfo);
            return 0;
        } else {
          // echo $status_eamil."Message sent!恭喜，邮件发送成功！";
       //return array("error"=>1,"恭喜，邮件发送成功！"); 
            return 1;
        }

}

function gotomail($mail) {
    $temp=explode('@',$mail);
    $t=strtolower($temp[1]);
 
    if ($t=='163.com') {
        return 'mail.163.com';
    } else if ($t=='vip.163.com') {
        return 'vip.163.com';
    } else if ($t=='126.com') {
        return 'mail.126.com';
    } else if ($t=='qq.com' || $t=='vip.qq.com' || $t=='foxmail.com') {
        return 'mail.qq.com';
    } else if ($t=='gmail.com') {
        return 'mail.google.com';
    } else if ($t=='sohu.com') {
        return 'mail.sohu.com';
    } else if ($t=='tom.com') {
        return 'mail.tom.com';
    } else if ($t=='vip.sina.com') {
        return 'vip.sina.com';
    } else if ($t=='sina.com.cn' || $t=='sina.com') {
        return 'mail.sina.com.cn';
    } else if ($t=='tom.com') {
        return 'mail.tom.com';
    } else if ($t=='yahoo.com.cn' || $t=='yahoo.cn') {
        return 'mail.cn.yahoo.com';
    } else if ($t=='tom.com') {
        return 'mail.tom.com';
    } else if ($t=='yeah.net') {
        return 'www.yeah.net';
    } else if ($t=='21cn.com') {
        return 'mail.21cn.com';
    } else if ($t=='hotmail.com') {
        return 'www.hotmail.com';
    } else if ($t=='sogou.com') {
        return 'mail.sogou.com';
    } else if ($t=='188.com') {
        return 'www.188.com';
    } else if ($t=='139.com') {
        return 'mail.10086.cn';
    } else if ($t=='189.cn') {
        return 'webmail15.189.cn/webmail';
    } else if ($t=='wo.com.cn') {
        return 'mail.wo.com.cn/smsmail';
    } else if ($t=='139.com') {
        return 'mail.10086.cn';
    } else {
        return '';
    }
}




function get_verification_code($w,$h)
    {

      $im = imagecreate($w, $h);

      //imagecolorallocate($im, 14, 114, 180); // background color
      $red = imagecolorallocate($im, 255, 0, 0);
      $white = imagecolorallocate($im, 255, 255, 255);

      $num1 = rand(1, 20);
      $num2 = rand(1, 20);

      $_SESSION['code'] = $num1 + $num2;

      $gray = imagecolorallocate($im, 118, 151, 199);
      $black = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));

      //画背景
      imagefilledrectangle($im, 0, 0, 100, 24, $black);
      //在画布上随机生成大量点，起干扰作用;
      for ($i = 0; $i < 80; $i++) {
        imagesetpixel($im, rand(0, $w), rand(0, $h), $gray);
      }

      imagestring($im, 5, 5, 4, $num1, $red);
      imagestring($im, 5, 30, 3, "+", $red);
      imagestring($im, 5, 45, 4, $num2, $red);
      imagestring($im, 5, 70, 3, "=", $red);
      imagestring($im, 5, 80, 2, "?", $white);

      header("Content-type: image/png");
      imagepng($im);
      imagedestroy($im);
    }
?>
